var http = require('../utils/httpHelper.js');
var temp = require('./temporary/goodsData.js');

const setPromise = data => {
    return new Promise((resolve, reject) => {
        resolve(data);
    });
}


var dev = false; // getApp().globalData.dev;
if (dev) {
    console.log(temp);
    var findHomeCatList = () => setPromise(temp.findHomeCatListData);
    var findProdListByACatList = () => setPromise(temp.findProdListByACatListData);
    var cartList = () => setPromise(temp.cartListData);
} else {
    var findHomeCatList = () => http.get('/ssmall/admin/prod/findHomeCatList', {});
    var findProdListByACatList = (catAList, pageIndex, pageSize) =>
        http.get('/ssmall/common/prod/findProdListByACatList', {
            catAList,
            page: pageIndex,
            rows: pageSize
        });
    var findProdById = (prodId) => http.get('/ssmall/common/prod/findProdById?prodId=' + prodId);
    var findProdDescById = (prodId) => http.get('/ssmall/common/prod/findProdDescById?prodId=' + prodId);
    var cartList = (phone) => http.get('/ssmall/portal/cart/cartList?phone=' + phone);
    var findProdBySearchCondition = (keyword, catAList, bCatId, pageIndex, pageSize) =>
        http.get('/ssmall/common/prod/findProdBySearchCondition', {
            prodName: keyword,
            catAList,
            bCatId,
            status: 1,
            page: pageIndex,
            rows: pageSize
        });
    var findUserOrderList = (phone, status, pageIndex, pageSize) =>
        http.get('/ssmall/portal/order/findUserOrderList', {
            phone,
            status,
            page: pageIndex,
            rows: pageSize
        });
    var findOrderByOrderCode = (orderCode) => http.get('/ssmall/portal/order/findOrderByOrderCode', {
        orderCode
    });
}

module.exports = {
    findHomeCatList,
    findProdListByACatList,
    findProdById,
    findProdDescById,
    cartList,
    findProdBySearchCondition,
    findUserOrderList,
    findOrderByOrderCode,
};